package main

func minimumTotal(triangle [][]int) int {
	// 直接修改 源数据
	for i := 1; i < len(triangle); i++ {
		for j := 0; j < len(triangle[i]); j++ {
			// 由于是三角形，因此只需想要上下相邻比较获取 triangle[i-1][j]、triangle[i-1][j-1] && j != 0
			println(i, j)
			if j == 0 {
				triangle[i][j] += triangle[i-1][j]
			} else if j == len(triangle[i])-1 {
				triangle[i][j] += triangle[i-1][j-1]
			} else {
				triangle[i][j] += Min(triangle[i-1][j], triangle[i-1][j-1])
			}
		}
	}
	return MinArrNum(triangle[len(triangle)-1])
}

func MinArrNum(l []int) int {
	if l == nil || len(l) == 0 {
		return 0
	}
	minNum := l[0]
	for _, v := range l {
		if v < minNum {
			minNum = v
		}
	}
	return minNum
}

func Min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	r := minimumTotal([][]int{
		{2},
		{3, 4},
		{6, 5, 7}})
	println(r)
}
